<!-- 库存管理->库存报表 -->
<template>
    <div class="content-wrapper a-base-container">
        <div class="requisition-set-wrapper">
            <!-- 按钮 -->
            <div class="btn-wrapper clearfix">
                <a-row class="text-center clearfix">
                    <a-col :xs="24" :sm="24" :md="24" :lg="16" :xl="12">
                        <!-- <a-col :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns" @click="submitServer">
                                <a-icon class="btns-icon" type="save" />
                                <div class="btns-text">保存</div>
                            </div>
                        </a-col>
                        <a-col :class="voucherState==0?'':'btns-disable'" :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns" @click="voucherState==0?clickEdit():''">
                                <a-icon class="btns-icon" type="edit" />
                                <div class="btns-text">修改</div>
                            </div>
                        </a-col>
                        <a-col :class="orderId && voucherState==0?'':'btns-disable'" :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns" @click="orderId && voucherState==0?deleteOrder():''">
                                <a-icon class="btns-icon" type="delete" />
                                <div class="btns-text">删除</div>
                            </div>
                        </a-col>
                        <a-col :class="voucherState==0 && orderId?'':'btns-disable'" :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns" @click="voucherState==0 && orderId?auditClick(1):''">
                                <a-icon class="btns-icon" type="audit" />
                                <div class="btns-text">审核</div>
                            </div>
                        </a-col>
                        <a-col :class="voucherState==1 && orderId?'':'btns-disable'" :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns" @click="voucherState==1 && orderId?auditClick(0):''">
                                <a-icon class="btns-icon" type="audit" />
                                <div class="btns-text">弃审</div>
                            </div>
                        </a-col> -->
                        <a-col :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns" @click="printOrder">
                                <a-icon class="btns-icon" type="printer" />
                                <div class="btns-text">打印</div>
                            </div>
                        </a-col>
                        <!-- @click="showDrawerSetting" -->
                        <a-col :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns">
                                <a-icon class="btns-icon" type="setting" />
                                <div class="btns-text">导出</div>
                            </div>
                        </a-col>
                        <a-col :xs="btn_grid.xs" :sm="btn_grid.sm" :md="btn_grid.md" :lg="btn_grid.lg" :xl="btn_grid.xl">
                            <div class="btns" @click="getList">
                                <a-icon class="btns-icon" type="sync" />
                                <div class="btns-text">刷新</div>
                            </div>
                        </a-col>

                    </a-col>
                </a-row>
            </div>
            <div ref="print" class="documents-wrapper" id="documents-wrapper">
                <h3 class="text-center">
                    库存报表
                </h3>
                <div><span class="audit-status" v-show="voucherState==0">待审核</span><span class="audit-status" v-show="voucherState==1">已审</span></div>
                <div class="table-box">
                    <a-table :columns="columns" :data-source="dataSource" :pagination="pagination" :customRow="customClick" :scroll="{ x: 1000, y: 347 }" @change="onTableChange" :size="small" bordered>

                    </a-table>
                </div>
            </div>
        </div>
        <!--字段设置-->
        <a-drawer title="设置" placement="right" :closable="false" :visible="visibleDrawer" :after-visible-change="afterVisibleChange" @close="onClose" width="520">
            <a-tabs default-active-key="1" @change="callback">
                <a-tab-pane key="1" tab="表头">
                    <a-table></a-table>
                </a-tab-pane>
                <a-tab-pane key="2" tab="表体" force-render>
                    <a-table></a-table>
                </a-tab-pane>
            </a-tabs>
        </a-drawer>

    </div>
</template>
<script>


// import { save, examine, remove, getCode } from '@/api/inventory/inout';
import { getAction, postAction } from "@/api/manage";


// import pro from '@/mixins/procurement/pro'

export default {
    // mixins: [pro],
    data() {
        return {
            //----------↓样式----------
            btn_grid: {
                xs: 2,
                sm: 2,
                md: 2,
                lg: 2,
                xl: 2
            },
            formLayout: "inline",
            labelCol: { span: 8 },
            wrapperCol: { span: 16 },
            //----------↑样式----------
            dataSource: [],
            columns: [{
                title: '物料名称',
                dataIndex: 'inventoryName'
            }, {
                title: '物料编码',
                dataIndex: 'inventoryCode'
            }, {
                title: '仓库名称',
                dataIndex: 'warehouseName'
            }, {
                title: '现存量',
                dataIndex: 'inventoryQuantity',
            }],
            pagination: {
                size: "small",
                defaultPageSize: 10,
                current: 1,
                pageSize: 10,
                total: 0,
                showTotal: total => {
                    return (
                        <div>
                            共 {total} 条数据，每页
                            <a-input style="height:22px !important;width:3.2rem;"
                                value={this.pagination.pageSize}
                                min={1}
                                max={10}
                                size="small"
                                step={1}
                                onPressEnter={e => this.changePageSize(e)}
                            />
                      条
                        </div>
                    );
                },
                onChange: (page, pageSize) => {
                    this.pagination.current = page;
                    this.getList();
                },
            },
        };
    },
    created() {
        // this.initForm(1);
        this.getList();
    },
    methods: {
        showDrawerSetting() {
            //字段设计
            // this.visibleDrawer = true;
        },
        printOrder() {
            //打印
            this.$print(this.$refs.print);
        },
        onClose() {
            this.visibleDrawer = false;
        },
        //获取列表
        getList() {
            // console.log(this.orderHeaderData)
            // this.orderHeaderData.forEach(element => {
            //     if (element.code == 'warehouseId') {
            //         this.warehouseId = element.valueId;
            //     }
            // });
            let postData = {
                current: this.pagination.current,
                size: this.pagination.pageSize,
            }
            getAction('/in/inventoryInfo/pageList', postData).then(response => {
                if (response.code === 200) {
                    console.log(response.data.records);
                    this.dataSource = response.data.records;
                    this.pagination.total = response.data.total;
                }
            }).catch(error => { });
        },
        //保存
        submit(requestData) {
            save(requestData).then(response => {
                this.isSaveRun = true;
                if (response.code === 200) {
                    this.$message.success('保存成功');
                    this.getList();
                } else {
                    this.$message.error(response.message);
                }
            }).catch((e) => {
                this.isSaveRun = true;
            })
        },
        setValue(data) {
            const { orderHeaderData } = this;
            for (let i = 0; i < orderHeaderData.length; i++) {
                if (orderHeaderData[i].code == data.codesName) {
                    this.$set(orderHeaderData[i], 'value', data.name)
                    this.$set(orderHeaderData[i], 'valueId', data.id)
                    this.$set(orderHeaderData[i], 'valueName', data.name)
                    this.warehouseId = data.id;
                    break;
                }
            }
            Object.assign(this.orderHeaderData, orderHeaderData);

            this.getList();
        },
        //改变分页大小
        changePageSize(e) {
            const value = e.target.value;
            let size = Number.parseInt(value);
            if (!size) {
                size = 20;
            }
            if (size > 500) {
                size = 500;
            }
            Object.assign(this.pagination, {
                current: 1,
                pageSize: size,
            });

            this.getList();
        },
        //审核
        auditClick(type) {
            let requestData = {
                id: this.orderId,
                status: type
            }
            examine(requestData).then((response) => {
                if (response.code === 200) {
                    const backData = response.data;
                    if (type == 1) {
                        this.$message.success('审核成功');
                        this.editMask = true;
                        this.getList();
                    }
                    if (type == 0) {
                        this.$message.success('弃审成功');
                        this.editMask = false;
                        this.getList();
                    }
                } else {
                    // this.$message.warning(response.message);
                }
            })
        },
        //删除
        remove(postData) {
            remove(postData).then(response => {
                if (response.code === 200) {
                    this.$message.success('删除成功');
                    this.orderId = '';
                    this.voucherState = 0;
                    this.getList();//获取最新一条数据
                } else {
                    this.$message.error(response.message);
                }
            })
        },
        //获取单据编号
        getCode() {
            let data = {
                sourceCode: this.sourceCode
            }
            getCode(data).then((res) => {
                if (res.code == 200) {
                    this.receiptNumber = res.message;
                    for (let i = 0; i < this.orderHeaderData.length; i++) {
                        if (this.orderHeaderData[i].code == 'voucherCode') {
                            this.$set(this.orderHeaderData[i], 'onEdit', false)
                            this.$set(this.orderHeaderData[i], 'value', this.receiptNumber)
                        }
                    }
                } else {
                    // this.$message.warning(res.message);
                }
            });
        },
    }
};
</script>
<style lang="less">
@import "~@/style/purchase/voucher.less";
</style>